import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  //采购流程化
  {
    path:"/purchase",
    component:Layout,
    meta:{
      title:"采购流程",
      icon: 'plane',
    },
    children:[
      {
        path:"production-sc",
        name:"production-sc",
        component: () => import("@/views/purchaseprocess/productionSche"),
        meta:{
          icon:'dashboard',
          title:"生产部排期提交",
        }
      },
      {
        path:"technology-de",
        name:"technology-de",
        component: () => import("@/views/purchaseprocess/technologyDe"),
        meta:{
          icon:'example',
          title:"技术部需求提交",
        }
      },
      {
        path:"technology-analysis",
        name:"technology-analysis",
        component: () => import("@/views/purchaseprocess/analysis"),
        meta:{
          icon:'eye',
          title:"技术部需求解析",
        }
      },
      {
        path:"technology-his",
        name:"technology-his",
        component: () => import("@/views/purchaseprocess/TechDeHistory"),
        meta:{
          icon:'eye-open',
          title:"技术部提交历史",
        }
      },
      // {
      //   path:"production-de",
      //   name:"production-de",
      //   component: () => import("@/views/purchaseprocess/productionDe"),
      //   meta:{
      //     title:"生产部需求提交",
      //   }
      // },
      {
        path:"purchase-de",
        name:"purchase-de",
        component: () => import("@/views/purchaseprocess/purchaseDe"),
        meta:{
          icon:'form',
          title:"采购部图表",
        }
      },
    ]
  },
  {
    path:"/paymentPlan",
    component: Layout,
    meta:{
      icon:'link',
      title: "付款计划",
    },
    children: [
      {
        path: "due-receipt-detail",
        name:"due-receipt-detail",
        component: () => import("@/views/paymentPlan/dueReceiptDetail"),
        meta:{
          icon:'nested',
          title:"应付单文件提交"
        }
      },
      {
        path:"purchase-order-detail",
        name:"purchase-order-detail",
        component:() => import("@/views/paymentPlan/purchaseOrderDetail"),
        meta:{
          icon:'table',
          title:"采购订单明细提交",
        },
      },
      {
        path:"receipt-come-ledger",
        name:"receipt-come-ledger",
        component:() => import("@/views/paymentPlan/receiptComeLedger"),
        meta:{
          icon:'tree',
          title:"发票到票台账提交",
        },
      },
      {
        path:"supplier-account-period",
        name:"supplier-account-period",
        component:() => import("@/views/paymentPlan/supplierAccountPeriod"),
        meta:{
          icon:'tree',
          title:"供应商账期提交",
        },
      },
      {
        path:"dont-parse-supplier",
        name:"dont-parse-supplier",
        component:() => import("@/views/paymentPlan/dontParseSupplier"),
        meta:{
          icon:'table',
          title:"不解析供应商设置",
        },
      },
      {
        path:"payment-plan-analyse",
        name:"payment-plan-analyse",
        component:() => import("@/views/paymentPlan/paymentPlanAnalyse"),
        meta:{
          icon:'user',
          title:"付款计划分析",
        },
      },
    ]
  },
  {
    path:"/inventory",
    component: Layout,
    meta:{
      icon:'link',
      title: "库存分析",
    },
    children: [
      {
        path: "file-upload",
        name:"file-upload",
        component: () => import("@/views/inventory/fileUpload"),
        meta:{
          icon:'nested',
          title:"物料清单文件提交"
        }
      },
      {
        path:"inventory-age",
        name:"inventory-age",
        component:() => import("@/views/inventory/inventoryAge"),
        meta:{
          icon:'user',
          title:"库存账龄文件提交",
        },
      },
      {
        path:"production-shop",
        name:"production-shop",
        component:() => import("@/views/inventory/production_shop"),
        meta:{
          icon:'table',
          title:"生产车间文件提交",
        },
      },
      {
        path:"inventory-ana",
        name:"inventory-ana",
        component:() => import("@/views/inventory/inventoryAna"),
        meta:{
          icon:'tree',
          title:"库存统计分析",
        },
      },
    ]
  },
  //测试页面
  {
    path: '/',
    component: Layout,
    children: [{
      path: 'test',
      name: 'test',
      component: () => import('@/views/material/send-instructive'),
      meta: {
        title: '测试页面',
      }
    }]
  },
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
